import Vue from 'vue'
import Vuex from 'vuex'
import menu from './menu'
import role from './role'
import user from './user'
import cate from './cate'
import spec from './spec'
import goods from './goods'
import member from './member'
import banner from './banner'
import seck from './seck'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userinfo:sessionStorage.getItem('userinfo')?JSON.parse(sessionStorage.getItem('userinfo')) :null
  },
  getters: {
    getUser(state) {
      return state.userinfo
    }
  },
  mutations: {
    REQ_USERINFO(state, payload) {
      if (payload) {
        state.userinfo = payload
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      } else {
        //清空存储
        sessionStorage.removeItem('userinfo')
      }
      
    }
  },
  actions: {
    changeUserAction({ commit }, payload) {
      commit('REQ_USERINFO',payload)
    }
  },
  modules: {
    menu,
    role,
    user,
    cate,
    spec,
    goods,
    member,
    banner,
    seck
  }
})
